<template>
  <el-dialog
    title="转发动态"
    :visible="visible"
    width="460px"
    custom-class="circle-forward"
    :before-close="handleClose"
  >
    <div class="circle-forward__main" v-loading="loading">
      <div class="forward-header">
        <div class="picture" v-if="forwardData.attach_url.length > 0">
          <edu-image
            v-for="(item, index) in forwardData.attach_url.slice(0, 1)"
            :key="index"
            :src="item"
          ></edu-image>
        </div>
        <div class="signature">
          <span class="name">@{{ forwardData.nick_name }}：</span>{{ forwardData.content }}
        </div>
      </div>
      <div class="forward-input">
        <el-input
          type="textarea"
          :rows="3"
          placeholder="输入转发内容～"
          v-model="textarea"
        ></el-input>
      </div>
    </div>
    <template v-if="!loading" slot="footer">
      <el-button type="primary" size="mini" :disabled="disabledValue" @click="handleForwardSubmit"
        >转发</el-button
      >
    </template>
  </el-dialog>
</template>

<script>
export default {
  props: {
    visible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      textarea: '',
      loading: true,
      forwardData: {
        attach_url: [],
        nick_name: '',
        content: ''
      }
    }
  },
  computed: {
    disabledValue() {
      return this.textarea.length < 3
    }
  },
  methods: {
    // 关闭
    handleClose() {
      this.$emit('update:visible', false)
      setTimeout(() => {
        this.textarea = ''
      }, 200)
    },
    // 发布
    handleForwardSubmit() {
      this.handleClose()
      this.$api.createCircleRecircle(
        {
          orignal_id: this.forwardData.id,
          owner_id: this.forwardData.user_id,
          content: this.textarea
        },
        res => {
          this.$message.success(res.msg)
          this.$emit('update')
        },
        err => {
          this.$message.error(err.msg)
        }
      )
    },
    // 获取数据
    getForwardData(id) {
      this.loading = true
      this.$api.getCircleRecircle(
        {
          orignal_id: id
        },
        res => {
          this.forwardData = res.data
          setTimeout(() => {
            this.loading = false
          }, 200)
        }
      )
    }
  }
}
</script>
<style lang="scss">
.circle-forward {
  .el-dialog__header {
    border-bottom: 1px solid #ebeef5;
  }
}
</style>
<style lang="scss" scoped>
.circle-forward {
  &__main {
    .forward-header {
      display: flex;
      align-items: center;
      background: #f7f7f7;
      padding: 10px;
      .picture {
        margin-right: 10px;
        .el-image {
          width: 48px;
          height: 48px;
        }
      }
      .signature {
        flex: 1;
        min-width: 0;
        font-size: 12px;
        font-weight: 400;
        color: $text-color-auxiliary;
        line-height: 18px;
        @include ellipsisLine(2);
        .name {
          color: $text-color-import;
        }
      }
    }
    .forward-input {
      margin-top: 10px;
    }
  }
}
</style>
